package com.syl.auth.model;

import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName SmallUserInfo
 * @Description 自定义用户信息
 * @Author YunLong
 * @Date 2023/4/27 21:57
 */
@Data
public class SmallUserInfo implements UserDetails {

    /**
     * 账号id
     **/
    private Long id;
    /**
     * 手机号
     **/
    private String phone;
    /**
     * 用户名
     **/
    private String username;
    /**
     * 密码
     **/
    private String password;
    private Long orgId;
    private String orgName;
    /**
     * 角色集合
     */
    private List<String> roleList;

    /**
     * @Author YunLong
     * @Date 2023/4/27 21:58
     * @Description 获取用户拥有的角色
     * 此处为角色Id列表。若使用注解方方式控制权限，此处需要给每个角色加 "ROLE_" 前缀。示例：ROLE_ADMIN
     **/
    @Override
    public Collection<GrantedAuthority> getAuthorities() {
        return roleList.stream()
                .map(SimpleGrantedAuthority::new)
                .collect(Collectors.toList());
    }

    @Override
    public String getPassword() {
        return this.password;
    }

    @Override
    public String getUsername() {
        return this.username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }


}
